﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using GPSTrackingDBV2.Entities;
using GPSTrackingDBV2.Data;

#endregion

namespace GPSTrackingDBV2.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="GeoFencesProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class GeoFencesProviderBaseCore : EntityProviderBase<GPSTrackingDBV2.Entities.GeoFences, GPSTrackingDBV2.Entities.GeoFencesKey>
	{		
		#region Get from Many To Many Relationship Functions
		#region GetByCompanyIdFromCompaniesByGeoFences
		
		/// <summary>
		///		Gets GeoFences objects from the datasource by CompanyID in the
		///		CompaniesByGeoFences table. Table GeoFences is related to table Companies
		///		through the (M:N) relationship defined in the CompaniesByGeoFences table.
		/// </summary>
		/// <param name="_companyId"></param>
		/// <returns>Returns a typed collection of GeoFences objects.</returns>
		public TList<GeoFences> GetByCompanyIdFromCompaniesByGeoFences(System.Int32 _companyId)
		{
			int count = -1;
			return GetByCompanyIdFromCompaniesByGeoFences(null,_companyId, 0, int.MaxValue, out count);
			
		}
		
		/// <summary>
		///		Gets GPSTrackingDBV2.Entities.GeoFences objects from the datasource by CompanyID in the
		///		CompaniesByGeoFences table. Table GeoFences is related to table Companies
		///		through the (M:N) relationship defined in the CompaniesByGeoFences table.
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_companyId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of GeoFences objects.</returns>
		public TList<GeoFences> GetByCompanyIdFromCompaniesByGeoFences(System.Int32 _companyId, int start, int pageLength)
		{
			int count = -1;
			return GetByCompanyIdFromCompaniesByGeoFences(null, _companyId, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets GeoFences objects from the datasource by CompanyID in the
		///		CompaniesByGeoFences table. Table GeoFences is related to table Companies
		///		through the (M:N) relationship defined in the CompaniesByGeoFences table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_companyId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GeoFences objects.</returns>
		public TList<GeoFences> GetByCompanyIdFromCompaniesByGeoFences(TransactionManager transactionManager, System.Int32 _companyId)
		{
			int count = -1;
			return GetByCompanyIdFromCompaniesByGeoFences(transactionManager, _companyId, 0, int.MaxValue, out count);
		}
		
		
		/// <summary>
		///		Gets GeoFences objects from the datasource by CompanyID in the
		///		CompaniesByGeoFences table. Table GeoFences is related to table Companies
		///		through the (M:N) relationship defined in the CompaniesByGeoFences table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_companyId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GeoFences objects.</returns>
		public TList<GeoFences> GetByCompanyIdFromCompaniesByGeoFences(TransactionManager transactionManager, System.Int32 _companyId,int start, int pageLength)
		{
			int count = -1;
			return GetByCompanyIdFromCompaniesByGeoFences(transactionManager, _companyId, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets GeoFences objects from the datasource by CompanyID in the
		///		CompaniesByGeoFences table. Table GeoFences is related to table Companies
		///		through the (M:N) relationship defined in the CompaniesByGeoFences table.
		/// </summary>
		/// <param name="_companyId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GeoFences objects.</returns>
		public TList<GeoFences> GetByCompanyIdFromCompaniesByGeoFences(System.Int32 _companyId,int start, int pageLength, out int count)
		{
			
			return GetByCompanyIdFromCompaniesByGeoFences(null, _companyId, start, pageLength, out count);
		}


		/// <summary>
		///		Gets GeoFences objects from the datasource by CompanyID in the
		///		CompaniesByGeoFences table. Table GeoFences is related to table Companies
		///		through the (M:N) relationship defined in the CompaniesByGeoFences table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <param name="_companyId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of GeoFences objects.</returns>
		public abstract TList<GeoFences> GetByCompanyIdFromCompaniesByGeoFences(TransactionManager transactionManager,System.Int32 _companyId, int start, int pageLength, out int count);
		
		#endregion GetByCompanyIdFromCompaniesByGeoFences
		
		#region GetByGpsImeiFromGeoFencesByGpsStock
		
		/// <summary>
		///		Gets GeoFences objects from the datasource by GPSImei in the
		///		GeoFencesByGPSStock table. Table GeoFences is related to table GPSStock
		///		through the (M:N) relationship defined in the GeoFencesByGPSStock table.
		/// </summary>
		/// <param name="_gpsImei"></param>
		/// <returns>Returns a typed collection of GeoFences objects.</returns>
		public TList<GeoFences> GetByGpsImeiFromGeoFencesByGpsStock(System.String _gpsImei)
		{
			int count = -1;
			return GetByGpsImeiFromGeoFencesByGpsStock(null,_gpsImei, 0, int.MaxValue, out count);
			
		}
		
		/// <summary>
		///		Gets GPSTrackingDBV2.Entities.GeoFences objects from the datasource by GPSImei in the
		///		GeoFencesByGPSStock table. Table GeoFences is related to table GPSStock
		///		through the (M:N) relationship defined in the GeoFencesByGPSStock table.
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_gpsImei"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of GeoFences objects.</returns>
		public TList<GeoFences> GetByGpsImeiFromGeoFencesByGpsStock(System.String _gpsImei, int start, int pageLength)
		{
			int count = -1;
			return GetByGpsImeiFromGeoFencesByGpsStock(null, _gpsImei, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets GeoFences objects from the datasource by GPSImei in the
		///		GeoFencesByGPSStock table. Table GeoFences is related to table GPSStock
		///		through the (M:N) relationship defined in the GeoFencesByGPSStock table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_gpsImei"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GeoFences objects.</returns>
		public TList<GeoFences> GetByGpsImeiFromGeoFencesByGpsStock(TransactionManager transactionManager, System.String _gpsImei)
		{
			int count = -1;
			return GetByGpsImeiFromGeoFencesByGpsStock(transactionManager, _gpsImei, 0, int.MaxValue, out count);
		}
		
		
		/// <summary>
		///		Gets GeoFences objects from the datasource by GPSImei in the
		///		GeoFencesByGPSStock table. Table GeoFences is related to table GPSStock
		///		through the (M:N) relationship defined in the GeoFencesByGPSStock table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_gpsImei"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GeoFences objects.</returns>
		public TList<GeoFences> GetByGpsImeiFromGeoFencesByGpsStock(TransactionManager transactionManager, System.String _gpsImei,int start, int pageLength)
		{
			int count = -1;
			return GetByGpsImeiFromGeoFencesByGpsStock(transactionManager, _gpsImei, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets GeoFences objects from the datasource by GPSImei in the
		///		GeoFencesByGPSStock table. Table GeoFences is related to table GPSStock
		///		through the (M:N) relationship defined in the GeoFencesByGPSStock table.
		/// </summary>
		/// <param name="_gpsImei"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GeoFences objects.</returns>
		public TList<GeoFences> GetByGpsImeiFromGeoFencesByGpsStock(System.String _gpsImei,int start, int pageLength, out int count)
		{
			
			return GetByGpsImeiFromGeoFencesByGpsStock(null, _gpsImei, start, pageLength, out count);
		}


		/// <summary>
		///		Gets GeoFences objects from the datasource by GPSImei in the
		///		GeoFencesByGPSStock table. Table GeoFences is related to table GPSStock
		///		through the (M:N) relationship defined in the GeoFencesByGPSStock table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <param name="_gpsImei"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of GeoFences objects.</returns>
		public abstract TList<GeoFences> GetByGpsImeiFromGeoFencesByGpsStock(TransactionManager transactionManager,System.String _gpsImei, int start, int pageLength, out int count);
		
		#endregion GetByGpsImeiFromGeoFencesByGpsStock
		
		#region GetByGpsImeiFromNotificationByGeoFencesByGpsStock
		
		/// <summary>
		///		Gets GeoFences objects from the datasource by GPSImei in the
		///		NotificationByGeoFencesByGPSStock table. Table GeoFences is related to table GPSStock
		///		through the (M:N) relationship defined in the NotificationByGeoFencesByGPSStock table.
		/// </summary>
		/// <param name="_gpsImei"></param>
		/// <returns>Returns a typed collection of GeoFences objects.</returns>
		public TList<GeoFences> GetByGpsImeiFromNotificationByGeoFencesByGpsStock(System.String _gpsImei)
		{
			int count = -1;
			return GetByGpsImeiFromNotificationByGeoFencesByGpsStock(null,_gpsImei, 0, int.MaxValue, out count);
			
		}
		
		/// <summary>
		///		Gets GPSTrackingDBV2.Entities.GeoFences objects from the datasource by GPSImei in the
		///		NotificationByGeoFencesByGPSStock table. Table GeoFences is related to table GPSStock
		///		through the (M:N) relationship defined in the NotificationByGeoFencesByGPSStock table.
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_gpsImei"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of GeoFences objects.</returns>
		public TList<GeoFences> GetByGpsImeiFromNotificationByGeoFencesByGpsStock(System.String _gpsImei, int start, int pageLength)
		{
			int count = -1;
			return GetByGpsImeiFromNotificationByGeoFencesByGpsStock(null, _gpsImei, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets GeoFences objects from the datasource by GPSImei in the
		///		NotificationByGeoFencesByGPSStock table. Table GeoFences is related to table GPSStock
		///		through the (M:N) relationship defined in the NotificationByGeoFencesByGPSStock table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_gpsImei"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GeoFences objects.</returns>
		public TList<GeoFences> GetByGpsImeiFromNotificationByGeoFencesByGpsStock(TransactionManager transactionManager, System.String _gpsImei)
		{
			int count = -1;
			return GetByGpsImeiFromNotificationByGeoFencesByGpsStock(transactionManager, _gpsImei, 0, int.MaxValue, out count);
		}
		
		
		/// <summary>
		///		Gets GeoFences objects from the datasource by GPSImei in the
		///		NotificationByGeoFencesByGPSStock table. Table GeoFences is related to table GPSStock
		///		through the (M:N) relationship defined in the NotificationByGeoFencesByGPSStock table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_gpsImei"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GeoFences objects.</returns>
		public TList<GeoFences> GetByGpsImeiFromNotificationByGeoFencesByGpsStock(TransactionManager transactionManager, System.String _gpsImei,int start, int pageLength)
		{
			int count = -1;
			return GetByGpsImeiFromNotificationByGeoFencesByGpsStock(transactionManager, _gpsImei, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets GeoFences objects from the datasource by GPSImei in the
		///		NotificationByGeoFencesByGPSStock table. Table GeoFences is related to table GPSStock
		///		through the (M:N) relationship defined in the NotificationByGeoFencesByGPSStock table.
		/// </summary>
		/// <param name="_gpsImei"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GeoFences objects.</returns>
		public TList<GeoFences> GetByGpsImeiFromNotificationByGeoFencesByGpsStock(System.String _gpsImei,int start, int pageLength, out int count)
		{
			
			return GetByGpsImeiFromNotificationByGeoFencesByGpsStock(null, _gpsImei, start, pageLength, out count);
		}


		/// <summary>
		///		Gets GeoFences objects from the datasource by GPSImei in the
		///		NotificationByGeoFencesByGPSStock table. Table GeoFences is related to table GPSStock
		///		through the (M:N) relationship defined in the NotificationByGeoFencesByGPSStock table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <param name="_gpsImei"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of GeoFences objects.</returns>
		public abstract TList<GeoFences> GetByGpsImeiFromNotificationByGeoFencesByGpsStock(TransactionManager transactionManager,System.String _gpsImei, int start, int pageLength, out int count);
		
		#endregion GetByGpsImeiFromNotificationByGeoFencesByGpsStock
		
		#region GetByNotificationIdFromNotificationByGeoFencesByGpsStock
		
		/// <summary>
		///		Gets GeoFences objects from the datasource by NotificationID in the
		///		NotificationByGeoFencesByGPSStock table. Table GeoFences is related to table Notifications
		///		through the (M:N) relationship defined in the NotificationByGeoFencesByGPSStock table.
		/// </summary>
		/// <param name="_notificationId"></param>
		/// <returns>Returns a typed collection of GeoFences objects.</returns>
		public TList<GeoFences> GetByNotificationIdFromNotificationByGeoFencesByGpsStock(System.Int32 _notificationId)
		{
			int count = -1;
			return GetByNotificationIdFromNotificationByGeoFencesByGpsStock(null,_notificationId, 0, int.MaxValue, out count);
			
		}
		
		/// <summary>
		///		Gets GPSTrackingDBV2.Entities.GeoFences objects from the datasource by NotificationID in the
		///		NotificationByGeoFencesByGPSStock table. Table GeoFences is related to table Notifications
		///		through the (M:N) relationship defined in the NotificationByGeoFencesByGPSStock table.
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_notificationId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of GeoFences objects.</returns>
		public TList<GeoFences> GetByNotificationIdFromNotificationByGeoFencesByGpsStock(System.Int32 _notificationId, int start, int pageLength)
		{
			int count = -1;
			return GetByNotificationIdFromNotificationByGeoFencesByGpsStock(null, _notificationId, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets GeoFences objects from the datasource by NotificationID in the
		///		NotificationByGeoFencesByGPSStock table. Table GeoFences is related to table Notifications
		///		through the (M:N) relationship defined in the NotificationByGeoFencesByGPSStock table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_notificationId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GeoFences objects.</returns>
		public TList<GeoFences> GetByNotificationIdFromNotificationByGeoFencesByGpsStock(TransactionManager transactionManager, System.Int32 _notificationId)
		{
			int count = -1;
			return GetByNotificationIdFromNotificationByGeoFencesByGpsStock(transactionManager, _notificationId, 0, int.MaxValue, out count);
		}
		
		
		/// <summary>
		///		Gets GeoFences objects from the datasource by NotificationID in the
		///		NotificationByGeoFencesByGPSStock table. Table GeoFences is related to table Notifications
		///		through the (M:N) relationship defined in the NotificationByGeoFencesByGPSStock table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_notificationId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GeoFences objects.</returns>
		public TList<GeoFences> GetByNotificationIdFromNotificationByGeoFencesByGpsStock(TransactionManager transactionManager, System.Int32 _notificationId,int start, int pageLength)
		{
			int count = -1;
			return GetByNotificationIdFromNotificationByGeoFencesByGpsStock(transactionManager, _notificationId, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets GeoFences objects from the datasource by NotificationID in the
		///		NotificationByGeoFencesByGPSStock table. Table GeoFences is related to table Notifications
		///		through the (M:N) relationship defined in the NotificationByGeoFencesByGPSStock table.
		/// </summary>
		/// <param name="_notificationId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GeoFences objects.</returns>
		public TList<GeoFences> GetByNotificationIdFromNotificationByGeoFencesByGpsStock(System.Int32 _notificationId,int start, int pageLength, out int count)
		{
			
			return GetByNotificationIdFromNotificationByGeoFencesByGpsStock(null, _notificationId, start, pageLength, out count);
		}


		/// <summary>
		///		Gets GeoFences objects from the datasource by NotificationID in the
		///		NotificationByGeoFencesByGPSStock table. Table GeoFences is related to table Notifications
		///		through the (M:N) relationship defined in the NotificationByGeoFencesByGPSStock table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <param name="_notificationId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of GeoFences objects.</returns>
		public abstract TList<GeoFences> GetByNotificationIdFromNotificationByGeoFencesByGpsStock(TransactionManager transactionManager,System.Int32 _notificationId, int start, int pageLength, out int count);
		
		#endregion GetByNotificationIdFromNotificationByGeoFencesByGpsStock
		
		#region GetByUsernameCompanyIdFromNotificationByGeoFencesByGpsStock
		
		/// <summary>
		///		Gets GeoFences objects from the datasource by Username in the
		///		NotificationByGeoFencesByGPSStock table. Table GeoFences is related to table Users
		///		through the (M:N) relationship defined in the NotificationByGeoFencesByGPSStock table.
		/// </summary>
		/// <param name="_username"></param>
		/// <param name="_companyId"></param>
		/// <returns>Returns a typed collection of GeoFences objects.</returns>
		public TList<GeoFences> GetByUsernameCompanyIdFromNotificationByGeoFencesByGpsStock(System.String _username, System.Int32 _companyId)
		{
			int count = -1;
			return GetByUsernameCompanyIdFromNotificationByGeoFencesByGpsStock(null,_username, _companyId, 0, int.MaxValue, out count);
			
		}
		
		/// <summary>
		///		Gets GPSTrackingDBV2.Entities.GeoFences objects from the datasource by Username in the
		///		NotificationByGeoFencesByGPSStock table. Table GeoFences is related to table Users
		///		through the (M:N) relationship defined in the NotificationByGeoFencesByGPSStock table.
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_username"></param>
		/// <param name="_companyId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of GeoFences objects.</returns>
		public TList<GeoFences> GetByUsernameCompanyIdFromNotificationByGeoFencesByGpsStock(System.String _username, System.Int32 _companyId, int start, int pageLength)
		{
			int count = -1;
			return GetByUsernameCompanyIdFromNotificationByGeoFencesByGpsStock(null, _username, _companyId, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets GeoFences objects from the datasource by Username in the
		///		NotificationByGeoFencesByGPSStock table. Table GeoFences is related to table Users
		///		through the (M:N) relationship defined in the NotificationByGeoFencesByGPSStock table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_username"></param>
		/// <param name="_companyId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GeoFences objects.</returns>
		public TList<GeoFences> GetByUsernameCompanyIdFromNotificationByGeoFencesByGpsStock(TransactionManager transactionManager, System.String _username, System.Int32 _companyId)
		{
			int count = -1;
			return GetByUsernameCompanyIdFromNotificationByGeoFencesByGpsStock(transactionManager, _username, _companyId, 0, int.MaxValue, out count);
		}
		
		
		/// <summary>
		///		Gets GeoFences objects from the datasource by Username in the
		///		NotificationByGeoFencesByGPSStock table. Table GeoFences is related to table Users
		///		through the (M:N) relationship defined in the NotificationByGeoFencesByGPSStock table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_username"></param>
		/// <param name="_companyId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GeoFences objects.</returns>
		public TList<GeoFences> GetByUsernameCompanyIdFromNotificationByGeoFencesByGpsStock(TransactionManager transactionManager, System.String _username, System.Int32 _companyId,int start, int pageLength)
		{
			int count = -1;
			return GetByUsernameCompanyIdFromNotificationByGeoFencesByGpsStock(transactionManager, _username, _companyId, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets GeoFences objects from the datasource by Username in the
		///		NotificationByGeoFencesByGPSStock table. Table GeoFences is related to table Users
		///		through the (M:N) relationship defined in the NotificationByGeoFencesByGPSStock table.
		/// </summary>
		/// <param name="_username"></param>
		/// <param name="_companyId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GeoFences objects.</returns>
		public TList<GeoFences> GetByUsernameCompanyIdFromNotificationByGeoFencesByGpsStock(System.String _username, System.Int32 _companyId,int start, int pageLength, out int count)
		{
			
			return GetByUsernameCompanyIdFromNotificationByGeoFencesByGpsStock(null, _username, _companyId, start, pageLength, out count);
		}


		/// <summary>
		///		Gets GeoFences objects from the datasource by Username in the
		///		NotificationByGeoFencesByGPSStock table. Table GeoFences is related to table Users
		///		through the (M:N) relationship defined in the NotificationByGeoFencesByGPSStock table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <param name="_username"></param>
		/// <param name="_companyId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of GeoFences objects.</returns>
		public abstract TList<GeoFences> GetByUsernameCompanyIdFromNotificationByGeoFencesByGpsStock(TransactionManager transactionManager,System.String _username, System.Int32 _companyId, int start, int pageLength, out int count);
		
		#endregion GetByUsernameCompanyIdFromNotificationByGeoFencesByGpsStock
		
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, GPSTrackingDBV2.Entities.GeoFencesKey key)
		{
			return Delete(transactionManager, key.GeoFenceId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="_geoFenceId">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.Int32 _geoFenceId)
		{
			return Delete(null, _geoFenceId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_geoFenceId">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.Int32 _geoFenceId);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override GPSTrackingDBV2.Entities.GeoFences Get(TransactionManager transactionManager, GPSTrackingDBV2.Entities.GeoFencesKey key, int start, int pageLength)
		{
			return GetByGeoFenceId(transactionManager, key.GeoFenceId, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_GeoFences_1 index.
		/// </summary>
		/// <param name="_geoFenceId"></param>
		/// <returns>Returns an instance of the <see cref="GPSTrackingDBV2.Entities.GeoFences"/> class.</returns>
		public GPSTrackingDBV2.Entities.GeoFences GetByGeoFenceId(System.Int32 _geoFenceId)
		{
			int count = -1;
			return GetByGeoFenceId(null,_geoFenceId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_GeoFences_1 index.
		/// </summary>
		/// <param name="_geoFenceId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="GPSTrackingDBV2.Entities.GeoFences"/> class.</returns>
		public GPSTrackingDBV2.Entities.GeoFences GetByGeoFenceId(System.Int32 _geoFenceId, int start, int pageLength)
		{
			int count = -1;
			return GetByGeoFenceId(null, _geoFenceId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_GeoFences_1 index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_geoFenceId"></param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="GPSTrackingDBV2.Entities.GeoFences"/> class.</returns>
		public GPSTrackingDBV2.Entities.GeoFences GetByGeoFenceId(TransactionManager transactionManager, System.Int32 _geoFenceId)
		{
			int count = -1;
			return GetByGeoFenceId(transactionManager, _geoFenceId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_GeoFences_1 index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_geoFenceId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="GPSTrackingDBV2.Entities.GeoFences"/> class.</returns>
		public GPSTrackingDBV2.Entities.GeoFences GetByGeoFenceId(TransactionManager transactionManager, System.Int32 _geoFenceId, int start, int pageLength)
		{
			int count = -1;
			return GetByGeoFenceId(transactionManager, _geoFenceId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_GeoFences_1 index.
		/// </summary>
		/// <param name="_geoFenceId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="GPSTrackingDBV2.Entities.GeoFences"/> class.</returns>
		public GPSTrackingDBV2.Entities.GeoFences GetByGeoFenceId(System.Int32 _geoFenceId, int start, int pageLength, out int count)
		{
			return GetByGeoFenceId(null, _geoFenceId, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_GeoFences_1 index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_geoFenceId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="GPSTrackingDBV2.Entities.GeoFences"/> class.</returns>
		public abstract GPSTrackingDBV2.Entities.GeoFences GetByGeoFenceId(TransactionManager transactionManager, System.Int32 _geoFenceId, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a TList&lt;GeoFences&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="TList&lt;GeoFences&gt;"/></returns>
		public static TList<GeoFences> Fill(IDataReader reader, TList<GeoFences> rows, int start, int pageLength)
		{
			NetTiersProvider currentProvider = DataRepository.Provider;
            bool useEntityFactory = currentProvider.UseEntityFactory;
            bool enableEntityTracking = currentProvider.EnableEntityTracking;
            LoadPolicy currentLoadPolicy = currentProvider.CurrentLoadPolicy;
			Type entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;
			
			// advance to the starting row
			for (int i = 0; i < start; i++)
			{
				if (!reader.Read())
				return rows; // not enough rows, just return
			}
			for (int i = 0; i < pageLength; i++)
			{
				if (!reader.Read())
					break; // we are done
					
				string key = null;
				
				GPSTrackingDBV2.Entities.GeoFences c = null;
				if (useEntityFactory)
				{
					key = new System.Text.StringBuilder("GeoFences")
					.Append("|").Append((System.Int32)reader[((int)GeoFencesColumn.GeoFenceId - 1)]).ToString();
					c = EntityManager.LocateOrCreate<GeoFences>(
					key.ToString(), // EntityTrackingKey
					"GeoFences",  //Creational Type
					entityCreationFactoryType,  //Factory used to create entity
					enableEntityTracking); // Track this entity?
				}
				else
				{
					c = new GPSTrackingDBV2.Entities.GeoFences();
				}
				
				if (!enableEntityTracking ||
					c.EntityState == EntityState.Added ||
					(enableEntityTracking &&
					
						(
							(currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
							(currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
						)
					))
				{
					c.SuppressEntityEvents = true;
					c.GeoFenceId = (System.Int32)reader[((int)GeoFencesColumn.GeoFenceId - 1)];
					c.OriginalGeoFenceId = c.GeoFenceId;
					c.Name = (System.String)reader[((int)GeoFencesColumn.Name - 1)];
					c.IsActive = (System.Boolean)reader[((int)GeoFencesColumn.IsActive - 1)];
					c.Polygon = (reader.IsDBNull(((int)GeoFencesColumn.Polygon - 1)))?null:(System.Object)reader[((int)GeoFencesColumn.Polygon - 1)];
					c.EntityTrackingKey = key;
					c.AcceptChanges();
					c.SuppressEntityEvents = false;
				}
				rows.Add(c);
			}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="GPSTrackingDBV2.Entities.GeoFences"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="GPSTrackingDBV2.Entities.GeoFences"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, GPSTrackingDBV2.Entities.GeoFences entity)
		{
			if (!reader.Read()) return;
			
			entity.GeoFenceId = (System.Int32)reader[((int)GeoFencesColumn.GeoFenceId - 1)];
			entity.OriginalGeoFenceId = (System.Int32)reader["GeoFenceID"];
			entity.Name = (System.String)reader[((int)GeoFencesColumn.Name - 1)];
			entity.IsActive = (System.Boolean)reader[((int)GeoFencesColumn.IsActive - 1)];
			entity.Polygon = (reader.IsDBNull(((int)GeoFencesColumn.Polygon - 1)))?null:(System.Object)reader[((int)GeoFencesColumn.Polygon - 1)];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="GPSTrackingDBV2.Entities.GeoFences"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="GPSTrackingDBV2.Entities.GeoFences"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, GPSTrackingDBV2.Entities.GeoFences entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.GeoFenceId = (System.Int32)dataRow["GeoFenceID"];
			entity.OriginalGeoFenceId = (System.Int32)dataRow["GeoFenceID"];
			entity.Name = (System.String)dataRow["Name"];
			entity.IsActive = (System.Boolean)dataRow["isActive"];
			entity.Polygon = Convert.IsDBNull(dataRow["Polygon"]) ? null : (System.Object)dataRow["Polygon"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="GPSTrackingDBV2.Entities.GeoFences"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">GPSTrackingDBV2.Entities.GeoFences Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		public override void DeepLoad(TransactionManager transactionManager, GPSTrackingDBV2.Entities.GeoFences entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			// Deep load child collections  - Call GetByGeoFenceId methods when available
			
			#region CompanyIdCompaniesCollection_From_CompaniesByGeoFences
			// RelationshipType.ManyToMany
			if (CanDeepLoad(entity, "List<Companies>|CompanyIdCompaniesCollection_From_CompaniesByGeoFences", deepLoadType, innerList))
			{
				entity.CompanyIdCompaniesCollection_From_CompaniesByGeoFences = DataRepository.CompaniesProvider.GetByGeoFenceIdFromCompaniesByGeoFences(transactionManager, entity.GeoFenceId);			 
		
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'CompanyIdCompaniesCollection_From_CompaniesByGeoFences' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.CompanyIdCompaniesCollection_From_CompaniesByGeoFences != null)
				{
					deepHandles.Add("CompanyIdCompaniesCollection_From_CompaniesByGeoFences",
						new KeyValuePair<Delegate, object>((DeepLoadHandle< Companies >) DataRepository.CompaniesProvider.DeepLoad,
						new object[] { transactionManager, entity.CompanyIdCompaniesCollection_From_CompaniesByGeoFences, deep, deepLoadType, childTypes, innerList }
					));
				}
			}
			#endregion
			
			
			
			#region GeoFenceDetailsCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<GeoFenceDetails>|GeoFenceDetailsCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'GeoFenceDetailsCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.GeoFenceDetailsCollection = DataRepository.GeoFenceDetailsProvider.GetByGeoFenceId(transactionManager, entity.GeoFenceId);

				if (deep && entity.GeoFenceDetailsCollection.Count > 0)
				{
					deepHandles.Add("GeoFenceDetailsCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<GeoFenceDetails>) DataRepository.GeoFenceDetailsProvider.DeepLoad,
						new object[] { transactionManager, entity.GeoFenceDetailsCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region NotificationIdNotificationsCollection_From_NotificationByGeoFencesByGpsStock
			// RelationshipType.ManyToMany
			if (CanDeepLoad(entity, "List<Notifications>|NotificationIdNotificationsCollection_From_NotificationByGeoFencesByGpsStock", deepLoadType, innerList))
			{
				entity.NotificationIdNotificationsCollection_From_NotificationByGeoFencesByGpsStock = DataRepository.NotificationsProvider.GetByGeoFenceIdFromNotificationByGeoFencesByGpsStock(transactionManager, entity.GeoFenceId);			 
		
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'NotificationIdNotificationsCollection_From_NotificationByGeoFencesByGpsStock' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.NotificationIdNotificationsCollection_From_NotificationByGeoFencesByGpsStock != null)
				{
					deepHandles.Add("NotificationIdNotificationsCollection_From_NotificationByGeoFencesByGpsStock",
						new KeyValuePair<Delegate, object>((DeepLoadHandle< Notifications >) DataRepository.NotificationsProvider.DeepLoad,
						new object[] { transactionManager, entity.NotificationIdNotificationsCollection_From_NotificationByGeoFencesByGpsStock, deep, deepLoadType, childTypes, innerList }
					));
				}
			}
			#endregion
			
			
			
			#region GeoFencesByGpsStockCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<GeoFencesByGpsStock>|GeoFencesByGpsStockCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'GeoFencesByGpsStockCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.GeoFencesByGpsStockCollection = DataRepository.GeoFencesByGpsStockProvider.GetByGeoFenceId(transactionManager, entity.GeoFenceId);

				if (deep && entity.GeoFencesByGpsStockCollection.Count > 0)
				{
					deepHandles.Add("GeoFencesByGpsStockCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<GeoFencesByGpsStock>) DataRepository.GeoFencesByGpsStockProvider.DeepLoad,
						new object[] { transactionManager, entity.GeoFencesByGpsStockCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region GpsImeiGpsStockCollection_From_GeoFencesByGpsStock
			// RelationshipType.ManyToMany
			if (CanDeepLoad(entity, "List<GpsStock>|GpsImeiGpsStockCollection_From_GeoFencesByGpsStock", deepLoadType, innerList))
			{
				entity.GpsImeiGpsStockCollection_From_GeoFencesByGpsStock = DataRepository.GpsStockProvider.GetByGeoFenceIdFromGeoFencesByGpsStock(transactionManager, entity.GeoFenceId);			 
		
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'GpsImeiGpsStockCollection_From_GeoFencesByGpsStock' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.GpsImeiGpsStockCollection_From_GeoFencesByGpsStock != null)
				{
					deepHandles.Add("GpsImeiGpsStockCollection_From_GeoFencesByGpsStock",
						new KeyValuePair<Delegate, object>((DeepLoadHandle< GpsStock >) DataRepository.GpsStockProvider.DeepLoad,
						new object[] { transactionManager, entity.GpsImeiGpsStockCollection_From_GeoFencesByGpsStock, deep, deepLoadType, childTypes, innerList }
					));
				}
			}
			#endregion
			
			
			
			#region GpsImeiGpsStockCollection_From_NotificationByGeoFencesByGpsStock
			// RelationshipType.ManyToMany
			if (CanDeepLoad(entity, "List<GpsStock>|GpsImeiGpsStockCollection_From_NotificationByGeoFencesByGpsStock", deepLoadType, innerList))
			{
				entity.GpsImeiGpsStockCollection_From_NotificationByGeoFencesByGpsStock = DataRepository.GpsStockProvider.GetByGeoFenceIdFromNotificationByGeoFencesByGpsStock(transactionManager, entity.GeoFenceId);			 
		
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'GpsImeiGpsStockCollection_From_NotificationByGeoFencesByGpsStock' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.GpsImeiGpsStockCollection_From_NotificationByGeoFencesByGpsStock != null)
				{
					deepHandles.Add("GpsImeiGpsStockCollection_From_NotificationByGeoFencesByGpsStock",
						new KeyValuePair<Delegate, object>((DeepLoadHandle< GpsStock >) DataRepository.GpsStockProvider.DeepLoad,
						new object[] { transactionManager, entity.GpsImeiGpsStockCollection_From_NotificationByGeoFencesByGpsStock, deep, deepLoadType, childTypes, innerList }
					));
				}
			}
			#endregion
			
			
			
			#region UsernameCompanyIdUsersCollection_From_NotificationByGeoFencesByGpsStock
			// RelationshipType.ManyToMany
			if (CanDeepLoad(entity, "List<Users>|UsernameCompanyIdUsersCollection_From_NotificationByGeoFencesByGpsStock", deepLoadType, innerList))
			{
				entity.UsernameCompanyIdUsersCollection_From_NotificationByGeoFencesByGpsStock = DataRepository.UsersProvider.GetByGeoFenceIdFromNotificationByGeoFencesByGpsStock(transactionManager, entity.GeoFenceId);			 
		
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'UsernameCompanyIdUsersCollection_From_NotificationByGeoFencesByGpsStock' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.UsernameCompanyIdUsersCollection_From_NotificationByGeoFencesByGpsStock != null)
				{
					deepHandles.Add("UsernameCompanyIdUsersCollection_From_NotificationByGeoFencesByGpsStock",
						new KeyValuePair<Delegate, object>((DeepLoadHandle< Users >) DataRepository.UsersProvider.DeepLoad,
						new object[] { transactionManager, entity.UsernameCompanyIdUsersCollection_From_NotificationByGeoFencesByGpsStock, deep, deepLoadType, childTypes, innerList }
					));
				}
			}
			#endregion
			
			
			
			#region CompaniesByGeoFencesCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<CompaniesByGeoFences>|CompaniesByGeoFencesCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'CompaniesByGeoFencesCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.CompaniesByGeoFencesCollection = DataRepository.CompaniesByGeoFencesProvider.GetByGeoFenceId(transactionManager, entity.GeoFenceId);

				if (deep && entity.CompaniesByGeoFencesCollection.Count > 0)
				{
					deepHandles.Add("CompaniesByGeoFencesCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<CompaniesByGeoFences>) DataRepository.CompaniesByGeoFencesProvider.DeepLoad,
						new object[] { transactionManager, entity.CompaniesByGeoFencesCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region NotificationByGeoFencesByGpsStockCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<NotificationByGeoFencesByGpsStock>|NotificationByGeoFencesByGpsStockCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'NotificationByGeoFencesByGpsStockCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.NotificationByGeoFencesByGpsStockCollection = DataRepository.NotificationByGeoFencesByGpsStockProvider.GetByGeoFenceId(transactionManager, entity.GeoFenceId);

				if (deep && entity.NotificationByGeoFencesByGpsStockCollection.Count > 0)
				{
					deepHandles.Add("NotificationByGeoFencesByGpsStockCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<NotificationByGeoFencesByGpsStock>) DataRepository.NotificationByGeoFencesByGpsStockProvider.DeepLoad,
						new object[] { transactionManager, entity.NotificationByGeoFencesByGpsStockCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the GPSTrackingDBV2.Entities.GeoFences object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">GPSTrackingDBV2.Entities.GeoFences instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">GPSTrackingDBV2.Entities.GeoFences Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		public override bool DeepSave(TransactionManager transactionManager, GPSTrackingDBV2.Entities.GeoFences entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();

			#region CompanyIdCompaniesCollection_From_CompaniesByGeoFences>
			if (CanDeepSave(entity.CompanyIdCompaniesCollection_From_CompaniesByGeoFences, "List<Companies>|CompanyIdCompaniesCollection_From_CompaniesByGeoFences", deepSaveType, innerList))
			{
				if (entity.CompanyIdCompaniesCollection_From_CompaniesByGeoFences.Count > 0 || entity.CompanyIdCompaniesCollection_From_CompaniesByGeoFences.DeletedItems.Count > 0)
				{
					DataRepository.CompaniesProvider.Save(transactionManager, entity.CompanyIdCompaniesCollection_From_CompaniesByGeoFences); 
					deepHandles.Add("CompanyIdCompaniesCollection_From_CompaniesByGeoFences",
						new KeyValuePair<Delegate, object>((DeepSaveHandle<Companies>) DataRepository.CompaniesProvider.DeepSave,
						new object[] { transactionManager, entity.CompanyIdCompaniesCollection_From_CompaniesByGeoFences, deepSaveType, childTypes, innerList }
					));
				}
			}
			#endregion 

			#region NotificationIdNotificationsCollection_From_NotificationByGeoFencesByGpsStock>
			if (CanDeepSave(entity.NotificationIdNotificationsCollection_From_NotificationByGeoFencesByGpsStock, "List<Notifications>|NotificationIdNotificationsCollection_From_NotificationByGeoFencesByGpsStock", deepSaveType, innerList))
			{
				if (entity.NotificationIdNotificationsCollection_From_NotificationByGeoFencesByGpsStock.Count > 0 || entity.NotificationIdNotificationsCollection_From_NotificationByGeoFencesByGpsStock.DeletedItems.Count > 0)
				{
					DataRepository.NotificationsProvider.Save(transactionManager, entity.NotificationIdNotificationsCollection_From_NotificationByGeoFencesByGpsStock); 
					deepHandles.Add("NotificationIdNotificationsCollection_From_NotificationByGeoFencesByGpsStock",
						new KeyValuePair<Delegate, object>((DeepSaveHandle<Notifications>) DataRepository.NotificationsProvider.DeepSave,
						new object[] { transactionManager, entity.NotificationIdNotificationsCollection_From_NotificationByGeoFencesByGpsStock, deepSaveType, childTypes, innerList }
					));
				}
			}
			#endregion 

			#region GpsImeiGpsStockCollection_From_GeoFencesByGpsStock>
			if (CanDeepSave(entity.GpsImeiGpsStockCollection_From_GeoFencesByGpsStock, "List<GpsStock>|GpsImeiGpsStockCollection_From_GeoFencesByGpsStock", deepSaveType, innerList))
			{
				if (entity.GpsImeiGpsStockCollection_From_GeoFencesByGpsStock.Count > 0 || entity.GpsImeiGpsStockCollection_From_GeoFencesByGpsStock.DeletedItems.Count > 0)
				{
					DataRepository.GpsStockProvider.Save(transactionManager, entity.GpsImeiGpsStockCollection_From_GeoFencesByGpsStock); 
					deepHandles.Add("GpsImeiGpsStockCollection_From_GeoFencesByGpsStock",
						new KeyValuePair<Delegate, object>((DeepSaveHandle<GpsStock>) DataRepository.GpsStockProvider.DeepSave,
						new object[] { transactionManager, entity.GpsImeiGpsStockCollection_From_GeoFencesByGpsStock, deepSaveType, childTypes, innerList }
					));
				}
			}
			#endregion 

			#region GpsImeiGpsStockCollection_From_NotificationByGeoFencesByGpsStock>
			if (CanDeepSave(entity.GpsImeiGpsStockCollection_From_NotificationByGeoFencesByGpsStock, "List<GpsStock>|GpsImeiGpsStockCollection_From_NotificationByGeoFencesByGpsStock", deepSaveType, innerList))
			{
				if (entity.GpsImeiGpsStockCollection_From_NotificationByGeoFencesByGpsStock.Count > 0 || entity.GpsImeiGpsStockCollection_From_NotificationByGeoFencesByGpsStock.DeletedItems.Count > 0)
				{
					DataRepository.GpsStockProvider.Save(transactionManager, entity.GpsImeiGpsStockCollection_From_NotificationByGeoFencesByGpsStock); 
					deepHandles.Add("GpsImeiGpsStockCollection_From_NotificationByGeoFencesByGpsStock",
						new KeyValuePair<Delegate, object>((DeepSaveHandle<GpsStock>) DataRepository.GpsStockProvider.DeepSave,
						new object[] { transactionManager, entity.GpsImeiGpsStockCollection_From_NotificationByGeoFencesByGpsStock, deepSaveType, childTypes, innerList }
					));
				}
			}
			#endregion 

			#region UsernameCompanyIdUsersCollection_From_NotificationByGeoFencesByGpsStock>
			if (CanDeepSave(entity.UsernameCompanyIdUsersCollection_From_NotificationByGeoFencesByGpsStock, "List<Users>|UsernameCompanyIdUsersCollection_From_NotificationByGeoFencesByGpsStock", deepSaveType, innerList))
			{
				if (entity.UsernameCompanyIdUsersCollection_From_NotificationByGeoFencesByGpsStock.Count > 0 || entity.UsernameCompanyIdUsersCollection_From_NotificationByGeoFencesByGpsStock.DeletedItems.Count > 0)
				{
					DataRepository.UsersProvider.Save(transactionManager, entity.UsernameCompanyIdUsersCollection_From_NotificationByGeoFencesByGpsStock); 
					deepHandles.Add("UsernameCompanyIdUsersCollection_From_NotificationByGeoFencesByGpsStock",
						new KeyValuePair<Delegate, object>((DeepSaveHandle<Users>) DataRepository.UsersProvider.DeepSave,
						new object[] { transactionManager, entity.UsernameCompanyIdUsersCollection_From_NotificationByGeoFencesByGpsStock, deepSaveType, childTypes, innerList }
					));
				}
			}
			#endregion 
	
			#region List<GeoFenceDetails>
				if (CanDeepSave(entity.GeoFenceDetailsCollection, "List<GeoFenceDetails>|GeoFenceDetailsCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(GeoFenceDetails child in entity.GeoFenceDetailsCollection)
					{
						if(child.GeoFenceIdSource != null)
						{
							child.GeoFenceId = child.GeoFenceIdSource.GeoFenceId;
						}
						else
						{
							child.GeoFenceId = entity.GeoFenceId;
						}

					}

					if (entity.GeoFenceDetailsCollection.Count > 0 || entity.GeoFenceDetailsCollection.DeletedItems.Count > 0)
					{
						//DataRepository.GeoFenceDetailsProvider.Save(transactionManager, entity.GeoFenceDetailsCollection);
						
						deepHandles.Add("GeoFenceDetailsCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< GeoFenceDetails >) DataRepository.GeoFenceDetailsProvider.DeepSave,
							new object[] { transactionManager, entity.GeoFenceDetailsCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<GeoFencesByGpsStock>
				if (CanDeepSave(entity.GeoFencesByGpsStockCollection, "List<GeoFencesByGpsStock>|GeoFencesByGpsStockCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(GeoFencesByGpsStock child in entity.GeoFencesByGpsStockCollection)
					{
						if(child.GeoFenceIdSource != null)
						{
								child.GeoFenceId = child.GeoFenceIdSource.GeoFenceId;
						}

						if(child.GpsImeiSource != null)
						{
								child.GpsImei = child.GpsImeiSource.GpsImei;
						}

					}

					if (entity.GeoFencesByGpsStockCollection.Count > 0 || entity.GeoFencesByGpsStockCollection.DeletedItems.Count > 0)
					{
						//DataRepository.GeoFencesByGpsStockProvider.Save(transactionManager, entity.GeoFencesByGpsStockCollection);
						
						deepHandles.Add("GeoFencesByGpsStockCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< GeoFencesByGpsStock >) DataRepository.GeoFencesByGpsStockProvider.DeepSave,
							new object[] { transactionManager, entity.GeoFencesByGpsStockCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<CompaniesByGeoFences>
				if (CanDeepSave(entity.CompaniesByGeoFencesCollection, "List<CompaniesByGeoFences>|CompaniesByGeoFencesCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(CompaniesByGeoFences child in entity.CompaniesByGeoFencesCollection)
					{
						if(child.GeoFenceIdSource != null)
						{
								child.GeoFenceId = child.GeoFenceIdSource.GeoFenceId;
						}

						if(child.CompanyIdSource != null)
						{
								child.CompanyId = child.CompanyIdSource.CompanyId;
						}

					}

					if (entity.CompaniesByGeoFencesCollection.Count > 0 || entity.CompaniesByGeoFencesCollection.DeletedItems.Count > 0)
					{
						//DataRepository.CompaniesByGeoFencesProvider.Save(transactionManager, entity.CompaniesByGeoFencesCollection);
						
						deepHandles.Add("CompaniesByGeoFencesCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< CompaniesByGeoFences >) DataRepository.CompaniesByGeoFencesProvider.DeepSave,
							new object[] { transactionManager, entity.CompaniesByGeoFencesCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<NotificationByGeoFencesByGpsStock>
				if (CanDeepSave(entity.NotificationByGeoFencesByGpsStockCollection, "List<NotificationByGeoFencesByGpsStock>|NotificationByGeoFencesByGpsStockCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(NotificationByGeoFencesByGpsStock child in entity.NotificationByGeoFencesByGpsStockCollection)
					{
						if(child.GeoFenceIdSource != null)
						{
								child.GeoFenceId = child.GeoFenceIdSource.GeoFenceId;
						}

						if(child.NotificationIdSource != null)
						{
								child.NotificationId = child.NotificationIdSource.NotificationId;
						}

						if(child.GpsImeiSource != null)
						{
								child.GpsImei = child.GpsImeiSource.GpsImei;
						}

						if(child.UsernameCompanyIdSource != null)
						{
								child.Username = child.UsernameCompanyIdSource.Username;
								child.CompanyId = child.UsernameCompanyIdSource.CompanyId;
						}

					}

					if (entity.NotificationByGeoFencesByGpsStockCollection.Count > 0 || entity.NotificationByGeoFencesByGpsStockCollection.DeletedItems.Count > 0)
					{
						//DataRepository.NotificationByGeoFencesByGpsStockProvider.Save(transactionManager, entity.NotificationByGeoFencesByGpsStockCollection);
						
						deepHandles.Add("NotificationByGeoFencesByGpsStockCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< NotificationByGeoFencesByGpsStock >) DataRepository.NotificationByGeoFencesByGpsStockProvider.DeepSave,
							new object[] { transactionManager, entity.NotificationByGeoFencesByGpsStockCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region GeoFencesChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>GPSTrackingDBV2.Entities.GeoFences</c>
	///</summary>
	public enum GeoFencesChildEntityTypes
	{

		///<summary>
		/// Collection of <c>GeoFences</c> as ManyToMany for CompaniesCollection_From_CompaniesByGeoFences
		///</summary>
		[ChildEntityType(typeof(TList<Companies>))]
		CompanyIdCompaniesCollection_From_CompaniesByGeoFences,

		///<summary>
		/// Collection of <c>GeoFences</c> as OneToMany for GeoFenceDetailsCollection
		///</summary>
		[ChildEntityType(typeof(TList<GeoFenceDetails>))]
		GeoFenceDetailsCollection,

		///<summary>
		/// Collection of <c>GeoFences</c> as ManyToMany for NotificationsCollection_From_NotificationByGeoFencesByGpsStock
		///</summary>
		[ChildEntityType(typeof(TList<Notifications>))]
		NotificationIdNotificationsCollection_From_NotificationByGeoFencesByGpsStock,

		///<summary>
		/// Collection of <c>GeoFences</c> as OneToMany for GeoFencesByGpsStockCollection
		///</summary>
		[ChildEntityType(typeof(TList<GeoFencesByGpsStock>))]
		GeoFencesByGpsStockCollection,

		///<summary>
		/// Collection of <c>GeoFences</c> as ManyToMany for GpsStockCollection_From_GeoFencesByGpsStock
		///</summary>
		[ChildEntityType(typeof(TList<GpsStock>))]
		GpsImeiGpsStockCollection_From_GeoFencesByGpsStock,

		///<summary>
		/// Collection of <c>GeoFences</c> as ManyToMany for GpsStockCollection_From_NotificationByGeoFencesByGpsStock
		///</summary>
		[ChildEntityType(typeof(TList<GpsStock>))]
		GpsImeiGpsStockCollection_From_NotificationByGeoFencesByGpsStock,

		///<summary>
		/// Collection of <c>GeoFences</c> as ManyToMany for UsersCollection_From_NotificationByGeoFencesByGpsStock
		///</summary>
		[ChildEntityType(typeof(TList<Users>))]
		UsernameCompanyIdUsersCollection_From_NotificationByGeoFencesByGpsStock,

		///<summary>
		/// Collection of <c>GeoFences</c> as OneToMany for CompaniesByGeoFencesCollection
		///</summary>
		[ChildEntityType(typeof(TList<CompaniesByGeoFences>))]
		CompaniesByGeoFencesCollection,

		///<summary>
		/// Collection of <c>GeoFences</c> as OneToMany for NotificationByGeoFencesByGpsStockCollection
		///</summary>
		[ChildEntityType(typeof(TList<NotificationByGeoFencesByGpsStock>))]
		NotificationByGeoFencesByGpsStockCollection,
	}
	
	#endregion GeoFencesChildEntityTypes
	
	#region GeoFencesFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;GeoFencesColumn&gt;"/> class
	/// that is used exclusively with a <see cref="GeoFences"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class GeoFencesFilterBuilder : SqlFilterBuilder<GeoFencesColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the GeoFencesFilterBuilder class.
		/// </summary>
		public GeoFencesFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the GeoFencesFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public GeoFencesFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the GeoFencesFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public GeoFencesFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion GeoFencesFilterBuilder
	
	#region GeoFencesParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;GeoFencesColumn&gt;"/> class
	/// that is used exclusively with a <see cref="GeoFences"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class GeoFencesParameterBuilder : ParameterizedSqlFilterBuilder<GeoFencesColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the GeoFencesParameterBuilder class.
		/// </summary>
		public GeoFencesParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the GeoFencesParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public GeoFencesParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the GeoFencesParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public GeoFencesParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion GeoFencesParameterBuilder
	
	#region GeoFencesSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;GeoFencesColumn&gt;"/> class
	/// that is used exclusively with a <see cref="GeoFences"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class GeoFencesSortBuilder : SqlSortBuilder<GeoFencesColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the GeoFencesSqlSortBuilder class.
		/// </summary>
		public GeoFencesSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion GeoFencesSortBuilder
	
} // end namespace
